package com.ruoyi.hl.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.hl.reqbean.SHouHuanMyOutBloodBean;
import com.ruoyi.hl.reqbean.ShouHuanOutBean;
import com.ruoyi.hl.service.ShouHuanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "手环接受数据接口")
@RestController
@RequestMapping("/shouhuan")
public class ShouHuanReceiveController extends BaseController {


    @Autowired
    private ShouHuanService shouHuanService;

    @ApiOperation(value = "接收兔盯云数据") // 接口文档显示内容
    @PostMapping("/setDataFromOut")
    @ResponseBody
    public Object setDataFromOut(@Validated @RequestBody ShouHuanOutBean respon) {
        SHouHuanMyOutBloodBean myOutBloodBean = new SHouHuanMyOutBloodBean();
        myOutBloodBean.setCreated(respon.getData().getCreated());
        myOutBloodBean.setImei_sn(respon.getData().getImei_sn());
        myOutBloodBean.setUuid(respon.getData().getUuid());
        myOutBloodBean.setRouter(respon.getRouter());
        switch (respon.getRouter()) {
            case "device.blood":
                myOutBloodBean.setBlood_rate(respon.getData().getBlood_rate());
                shouHuanService.setBloodDataFromOut(myOutBloodBean);
                break;
            case "device.heart":
                myOutBloodBean.setHeart_rate(respon.getData().getHeart_rate());
                shouHuanService.setHeartDataFromOut(myOutBloodBean);
                break;
            case "device.temperature":
                myOutBloodBean.setTemperature(respon.getData().getTemperature());
                myOutBloodBean.setAppkey(respon.getData().getAppkey());
                shouHuanService.setTemperatureDataFromOut(myOutBloodBean);
                break;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("status", 0);
        map.put("message", "ok");
        return map;
    }


}
